package com.ruoyi.hualian.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.hualian.domain.*;
import com.ruoyi.hualian.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.ObjectUtils;
import org.aspectj.weaver.loadtime.Aj;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 华链 同步轮功能接口
 *
 * @author hujian
 */
@Api(tags = "同步轮功能接口")
@RestController
@RequestMapping("huaLian/timingPulley")
public class TimingPulleyController {

    @Autowired
    private IHlTimingPulleyService hlTimingPulleyService;

    /**
     * 华链同步轮及相关产品成本和利润
     * @param commodityCode 商品编码
     * @param consolePrinting 是否输出控制台打印日志
     * @return 结果
     */
    @PreAuthorize("@ss.lacksRole('tourist')")
    @ApiOperation("同步轮及相关产品成本和利润")
    @PostMapping("/costPrice")
    public AjaxResult costPrice(@ApiParam(name = "commodityCode", value = "商品编码", required = true) @RequestParam(value = "commodityCode", required = true) String commodityCode,
                                @ApiParam(name = "bandwidthW", value = "带宽W", required = false) @RequestParam(value = "bandwidthW", required = false) BigDecimal bandwidthW,
                                @ApiParam(name = "bandwidthL", value = "带宽L", required = false) @RequestParam(value = "bandwidthL", required = false) BigDecimal bandwidthL,
                                @ApiParam(name = "consolePrinting", value = "是否输出控制台打印日志", required = false) @RequestParam(value = "consolePrinting", required = false) Boolean consolePrinting,
                                @ApiParam(name = "authority", value = "价格显示范围", required = false) @RequestParam(value = "authority", required = false) String authority) {
        if (ObjectUtils.isEmpty(consolePrinting)) {
            consolePrinting = false;
        }
        if (!"1".equals(authority) && !"13711851155".equals(authority)) {
            return AjaxResult.error("权限错误");
        }
        return hlTimingPulleyService.costPrice(commodityCode, bandwidthW, bandwidthL, consolePrinting, authority);
    }

    /**
     * 华链同步轮及相关产品成本和利润
     * @param commodityCode 商品编码
     * @param consolePrinting 是否输出控制台打印日志
     * @return 结果
     */
    @PreAuthorize("@ss.hasRole('tourist')")
    @ApiOperation("同步轮及相关产品成本和利润")
    @PostMapping("/costPriceTourist")
    public AjaxResult costPriceTourist(@ApiParam(name = "commodityCode", value = "商品编码", required = true) @RequestParam(value = "commodityCode", required = true) String commodityCode,
                                @ApiParam(name = "bandwidthW", value = "带宽W", required = false) @RequestParam(value = "bandwidthW", required = false) BigDecimal bandwidthW,
                                @ApiParam(name = "bandwidthL", value = "带宽L", required = false) @RequestParam(value = "bandwidthL", required = false) BigDecimal bandwidthL,
                                @ApiParam(name = "consolePrinting", value = "是否输出控制台打印日志", required = false) @RequestParam(value = "consolePrinting", required = false) Boolean consolePrinting,
                                @ApiParam(name = "authority", value = "价格显示范围", required = false) @RequestParam(value = "authority", required = false) String authority) {
        if (ObjectUtils.isEmpty(consolePrinting)) {
            consolePrinting = false;
        }
        if (!"1".equals(authority) && !"13711851155".equals(authority)) {
            return AjaxResult.error("权限错误");
        }
        return hlTimingPulleyService.costPrice(commodityCode, bandwidthW, bandwidthL, consolePrinting, authority);
    }

    /**
     * 同步轮类型转换Excel
     */
    @ApiOperation("同步轮类型转换Excel")
    @PostMapping("/typeConvertExcel")
    public String typeConvertExcel(@ApiParam(name = "filePath", value = "文件路径", required = true) @RequestParam("filePath") String filePath,
                                    @ApiParam(name = "fileName", value = "文件名称", required = true) @RequestParam("fileName") String fileName,
                                    HttpServletResponse response) throws Exception {
        return hlTimingPulleyService.typeConvertExcel(filePath, fileName, response);
    }

    /**
     * 同步轮价格查询
     */
    @ApiOperation("同步轮价格查询")
    @PostMapping("/typePriceExcel")
    public String typePriceExcel(@ApiParam(name = "filePath", value = "文件路径", required = true) @RequestParam("filePath") String filePath,
                                   @ApiParam(name = "fileName", value = "文件名称", required = true) @RequestParam("fileName") String fileName,
                                   HttpServletResponse response) throws Exception {
        return hlTimingPulleyService.typePriceExcel(filePath, fileName, response);
    }


    /**
     * 怡和达同步轮类型转换网站
     */
    @ApiOperation("怡和达同步轮类型转换网站")
    @GetMapping("/yiHeDaTypeConvertWebsite/{yiHeDaTypeCommodity}")
    public AjaxResult yiHeDaTypeConvertWebsite(@PathVariable String yiHeDaTypeCommodity) throws Exception {
        return hlTimingPulleyService.yiHeDaTypeConvertWebsite(yiHeDaTypeCommodity);
    }

    /**
     * 米思米同步轮类型转换
     */
    @ApiOperation("米思米同步轮类型转换")
    @PostMapping("/miSiMiTypeConvert")
    public String miSiMiTypeConvert(@ApiParam(name = "filePath", value = "文件路径", required = true) @RequestParam("filePath") String filePath,
                                    @ApiParam(name = "fileName", value = "文件名称", required = true) @RequestParam("fileName") String fileName,
                                    HttpServletResponse response) throws Exception {
        return hlTimingPulleyService.miSiMiTypeConvert(filePath, fileName, response);
    }

    /**
     * 米思米同步轮类型转换网站
     */
    @ApiOperation("米思米同步轮类型转换网站")
    @GetMapping("/miSiMiTypeConvertWebsite/{miSiMiTypeCommodity}")
    public AjaxResult miSiMiTypeConvertWebsite(@PathVariable String miSiMiTypeCommodity) throws Exception {
        return hlTimingPulleyService.miSiMiTypeConvertWebsite(miSiMiTypeCommodity);
    }

    /**
     * 爱安特同步轮类型转换网站
     */
    @ApiOperation("爱安特同步轮类型转换网站")
    @GetMapping("/aiAnTeTypeConvertWebsite/{aiAnTeTypeCommodity}")
    public AjaxResult aiAnTeTypeConvertWebsite(@PathVariable String aiAnTeTypeCommodity) throws Exception {
        return hlTimingPulleyService.aiAnTeTypeConvert(aiAnTeTypeCommodity);
    }

    /**
     * 上隆同步轮类型转换网站
     */
    @ApiOperation("上隆同步轮类型转换网站")
    @GetMapping("/shangLongTypeConvertWebsite/{shangLongTypeCommodity}")
    public AjaxResult shangLongTypeConvertWebsite(@PathVariable String shangLongTypeCommodity) throws Exception {
        return hlTimingPulleyService.shangLongTypeConvert(shangLongTypeCommodity);
    }

    /**
     * 三益同步轮类型转换网站
     */
    @ApiOperation("三益同步轮类型转换网站")
    @GetMapping("/sanYiTypeConvertWebsite/{sanYiTypeCommodity}")
    public AjaxResult sanYiTypeConvertWebsite(@PathVariable String sanYiTypeCommodity) throws Exception {
        return hlTimingPulleyService.sanYiTypeConvert(sanYiTypeCommodity);
    }

    /**
     * 陌生型号类型转换网站
     */
    @ApiOperation("陌生型号类型转换网站")
    @GetMapping("/strangeTypeConvertWebsite/{strangeTypeCommodity}")
    public AjaxResult strangeTypeConvertWebsite(@PathVariable String strangeTypeCommodity) throws Exception {
        return hlTimingPulleyService.strangeTypeConvertWebsite(strangeTypeCommodity);
    }

    /**
     * 获取货期
     */
    @ApiOperation("获取货期")
    @GetMapping("/getDeliveryTime")
    public AjaxResult getDeliveryTime(@PathVariable String deliveryTime) throws Exception {
        return hlTimingPulleyService.getDeliveryTime(deliveryTime);
    }
}
